package cn.wanho.controller;

import cn.wanho.rvo.ResultVO;
import cn.wanho.service.exam.TeacherService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author zjy
 * @data 2022/8/5 13:51
 */
@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Resource
    private TeacherService teacherService;

    /**
     * @author zjy
     * @data 2022/8/5 13:51
     * @description 老师收到学生的复议申请，对有争议的题目进行二次批改
     */
    @PostMapping("/updateStudentScore")
    public ResultVO ModifyStudentGrades(Long subjectId, Integer score, Integer studentId, HttpServletRequest request) {
        //获取老师的ID
        Integer userId = (Integer) request.getAttribute("userId");
        return teacherService.updateStudentScore(subjectId, score, studentId, userId);
    }


    /**
     * @author zjy
     * @data 2022/8/5 16:59
     * @description
     */
    @GetMapping("/queryStudentId")
    public ResultVO queryStudentId(HttpServletRequest request) {
        Integer userId = (Integer) request.getAttribute("userId");
        return teacherService.queryAllStudent(userId);
    }

    /**
     * @author zl
     * @data 2022/8/5 16:59
     * @description
     */
    @GetMapping("/queryRecentClass")
    public ResultVO queryRecentCLass(HttpServletRequest request) throws Exception {
        return teacherService.queryRecentClass(request);
    }

    /**
     * @author zl
     * @data 2022/8/5 16:59
     * @description
     */
    @PostMapping("/uploadScore")
    public ResultVO uploadScore(Long subjectId,Integer studentId,Integer score,HttpServletRequest request) throws Exception {
        return teacherService.uploadScore(subjectId,studentId,score,request);
    }

    /**
     * @author zl
     * @data 2022/8/5 16:59
     * @description
     */
    @GetMapping("/queryPaperAnswer")
    public ResultVO queryPaperAnswer(Integer studentId,HttpServletRequest request) throws Exception {
        return teacherService.queryPaperAnswer(studentId,request);
    }

    /**
     * @author zl
     * @data 2022/8/5 16:59
     * @description
     */
    @RequestMapping("/createPaper")
    public ResultVO createPaper(String paperName, String startTime, String endTime, @RequestPart("file") MultipartFile file, HttpServletRequest request) throws Exception {
        System.out.println();
        return teacherService.createPaper(paperName,startTime,endTime,file,request);
    }


    @PostMapping("/passteacher")
    public ResultVO passTeacher(Integer tId,HttpServletRequest request){
        Integer id = (Integer) request.getAttribute("userId");
        return teacherService.passTeacher(id,tId);
    }

    @GetMapping("/queryAllTeacher")
    public ResultVO queryAllTeacher(HttpServletRequest request){
        Integer id = (Integer) request.getAttribute("userId");
        return teacherService.queryAllTeacher(id);
    }

}
